<?php

/**
 * LEAGUEMan
 *
 * Copyright (C) 2007 Marko Bischof
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
class LMSession
{
    static private $instance;

    const COMPONENT = "com_leagueman";

    private function __construct()
    {
        if (session_id() == '') {
            session_start();
        }

        if (!isset($_SESSION[self::COMPONENT])) {
            $_SESSION[self::COMPONENT] = array();
        }
    }

    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = new LMSession();
        }

        return self::$instance;
    }

    public function has($key)
    {
        return isset($_SESSION[self::COMPONENT][$key]);
    }

    public function set($key, $value)
    {
        $_SESSION[self::COMPONENT][$key] = $value;
    }

    public function get($key, $default = null)
    {
        if (isset($_SESSION[self::COMPONENT][$key])) {
            return $_SESSION[self::COMPONENT][$key];
        } else {
            return $default;
        }
    }

    public function delete($key)
    {
        unset($_SESSION[self::COMPONENT][$key]);
    }

}